import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 创建一个新的3D图形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 定义一些点的坐标
points = [(1, 1, 1), (2, 3, 2), (3, 2, 1), (5, 5, 5), (6, 4, 1)]

# 将点的坐标转换为numpy数组，以便matplotlib可以处理它们
points_np = np.array(points)

# 设置坐标轴的范围，使它们看起来等比例
max_range = np.array([points_np[:, 0].max() - points_np[:, 0].min(),
                      points_np[:, 1].max() - points_np[:, 1].min(),
                      points_np[:, 2].max() - points_np[:, 2].min()]).max()

Xb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][0].flatten() + points_np[:, 0].min()
Yb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][1].flatten() + points_np[:, 1].min()
Zb = 0.5 * max_range * np.mgrid[-1:2:2, -1:2:2, -1:2:2][2].flatten() + points_np[:, 2].min()

# 设置坐标轴范围
ax.set_xlim(points_np[:, 0].min() - 0.5 * max_range, points_np[:, 0].max() + 0.5 * max_range)
ax.set_ylim(points_np[:, 1].min() - 0.5 * max_range, points_np[:, 1].max() + 0.5 * max_range)
ax.set_zlim(points_np[:, 2].min() - 0.5 * max_range, points_np[:, 2].max() + 0.5 * max_range)

ax.grid(False)

# 添加坐标轴标签
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# 使用scatter方法绘制点
ax.scatter(points_np[:, 0], points_np[:, 1], points_np[:, 2], c='red', marker='o')

# 显示图形
plt.show()